#include <iostream>
#include <signal.h>

using namespace std;

volatile int flag = 0;

void catchSig(int signum)
{
    cout << "捕捉到一个信号：" << signum << endl;
    flag = 1;
    cout << "flag: " << flag << endl;
}

int main()
{
    signal(2, catchSig);
    while (!flag);
    cout << "进程退出" << endl;
    return 0;
}
